<?php
require_once(TEMPLATEPATH . '/wp-admin/notification-center.php');

/**
 * hook session
 * @author tuan
 */
add_action('init', 'startSession');
add_action('wp_logout', 'endSession');

foreach (glob(TEMPLATEPATH . "/model/*.php") as $filename) {
    include $filename;
}
include(TEMPLATEPATH . DIRECTORY_SEPARATOR . 'define.php');
foreach (glob(TEMPLATEPATH . "/helper/*.php") as $filename) {
    include $filename;
}

function startSession() {
    session_start();
}

function endSession() {
    session_destroy();
}

function redirectTo404Page() {
    global $wp_query;
    $wp_query->set_404();

    header('HTML/1.1 404 Not Found', true, 404);
    header('Status: 404 Not Found');
    include(get_template_directory() . '/404.php');
}





/*
 * @author:tham
 * add more menu in admin paged
 */

if (function_exists('wp_nav_menu')) {

    function wp_my_menus() {
        //đăng ký menu cho theme
        register_nav_menus(array('primary-menu' => __('Primary menu'),
            'second-menu' => __('second menu', 'Travel Donald')
        ));
    }
    
    add_action('init', 'wp_my_menus');
}
add_action('admin_menu', 'custom_meta_desc');

add_theme_support('custom-background', array(
    'default-color' => 'e6e6e6',
));
// post type post slider top
// Register Custom Post Type
function custom_post_type() {

    $labels = array(
        'name' => _x('Slider Top', 'Post Type General Name', 'text_domain'),
        'singular_name' => _x('Slider Top', 'Post Type Singular Name', 'text_domain'),
        'menu_name' => __('Slider Top', 'text_domain'),
        'parent_item_colon' => __('Parent Item:', 'text_domain'),
        'all_items' => __('All Items', 'text_domain'),
        'view_item' => __('View Item', 'text_domain'),
        'add_new_item' => __('Add New Item', 'text_domain'),
        'add_new' => __('Add New', 'text_domain'),
        'edit_item' => __('Edit Item', 'text_domain'),
        'update_item' => __('Update Item', 'text_domain'),
        'search_items' => __('Search Item', 'text_domain'),
        'not_found' => __('Not found', 'text_domain'),
        'not_found_in_trash' => __('Not found in Trash', 'text_domain'),
        'public' => true,
        'has_archive' => true,
    );

    $args = array(
        'label' => __('post_type', 'text_domain'),
        'description' => __('Post Type Description', 'text_domain'),
        'labels' => $labels,
        'supports' => array(),
        //'taxonomies'          => array( 'category', 'post_tag' ),
        'supports' => array('title', 'editor', 'thumbnail'),
        'hierarchical' => false,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 5,
        'menu_icon' => '',
        'can_export' => true,
        'has_archive' => true,
        'exclude_from_search' => false,
        'publicly_queryable' => true,
        'capability_type' => 'page',
    );
    register_post_type('type_slider', $args);
}


// Hook into the 'init' action
add_action('init', 'custom_post_type', 0);
add_theme_support('post-thumbnails', array('post', 'page', 'type_slider'));






// This theme uses a custom image size for featured images, displayed on "standard" posts.
add_theme_support('post-thumbnails');
set_post_thumbnail_size(624, 9999); // Unlimited height, soft crop


add_action('after_setup_theme', 'add_theme_support');


add_action('add_meta_boxes', 'ageFileUpload');
function ageFileUpload() {
    add_meta_box(
	    'ageBox', __('Upload files', 'wp_pony'), 'FileUpload_custom_box', $name_post_type_pony
    );
}
function FileUpload_custom_box($post) {
    
  global $post;
    ?>Upload file :
   <input type="hidden" name="template_directory_i" value='<?php bloginfo('template_directory'); ?>'/>
   <input type="hidden" name="post_id" id="post_id" value='<?php echo $post->ID ?>'/>
   <input type="file" name='file_upload1'  id='file_upload1'   />
   <input type="submit" value="Upload" name="btnUpVideo" id="btnUpVideo" /> <?php echo get_post_meta($post->ID,'_urlupload',true);   ?>
  
    <?php
 }
if(isset($_POST['btnUpVideo'])) {
                  global $post;
                     $post_id = $_REQUEST['post_id'];
                 // exit();
                        $tempDir = $_REQUEST['template_directory_i']; 
                        //print_r($_FILES);
                        if($_FILES['file_upload1']['name'] <> "")
                        {
							
                             $filename = $_FILES['file_upload1']['name'];

                             
                            move_uploaded_file($_FILES['file_upload1']['tmp_name'],"../wp-content/themes/travel_donald/upload/fileupload/".$filename);
                            $url_file1 = $filename;
                            
                            update_post_meta($post_id, '_urlupload', $url_file1);
                            
                        }
                       // echo 'AAAAAAAAAAAAAAA';
                       // exit();
}
add_action('save_post', 'save_custom_meta_desc');
function save_custom_meta_desc($post_id)
{
  
                        $tempDir = $_REQUEST['template_directory_i']; 
                        //print_r($_FILES);
                        if($_FILES['file_upload1']['name'] <> "")
                        {
							
                             $filename = $_FILES['file_upload1']['name'];

                             
                            move_uploaded_file($_FILES['file_upload1']['tmp_name'],"../wp-content/themes/travel_donald/upload/fileupload/".$filename);
                            $url_file1 = $filename;
                            
                            update_post_meta($post_id, '_urlupload', $url_file1);
                            
                        }
}
 
/*
 * Add site option oo admin
 * 
 */
require_once(TEMPLATEPATH . '/admin/admin-functions.php');
require_once(TEMPLATEPATH . '/admin/admin-interface.php');
require_once(TEMPLATEPATH . '/admin/theme-settings.php');

/**
 * get username based on email
 */
function getUserNameByEmail($email) {
    $aEmail = explode('@', $email);
    return $aEmail[0];
}
/*
 * function delete file
 */

function deleteFile($directory) {
    if (file_exists($directory)) {
	unlink($directory);
    }
}
